//系统用户管理
function BasicUser_main() {
    return $.layout({
        items: [{
            mapper: 'id,organName,organParentId.id,organType',
            id: 'BasicUse_BasicOrganization_main',
            top: [$.treeSearch],
            xtype: 'jtree',
            style: $.border('Right'),
            clazz: BasicOrganization,
            order: ['organSort->asc'],
            width: 200,
            region: 'west',
            where: [['organType', '=', 'area']],
            change: [{
                target: 'BasicUser_main',
                targetField: 'areaId.id'
            }]
        }, {
            autoLoad: false,
            clazz: BasicUser,
            itemSelector: 'div.list-view-a',
            pageSize: 10,
            region: 'center',
            id: 'BasicUser_main',
            xtype: 'jview',
            fields: ['positionId.positionName'],
            where: [['id', '!=', 'admin']],
            tpl: Ext
                .create(
                    'Ext.XTemplate',
                    '<tpl for=".">',
                    '<div class="list-view-a">',
                    '<div class="list-view-img"><img src="{[values.userImg]}" /><br/><span class="list-view-left">{[values["positionId.positionName"]]}</span><br/><br/><span class="{[this.getCls(values.state)]}">{[DICS.userState[values.state]]}</span></div>',
                    '<div class="list-view-right"><h3 style="color:#35BAF6;font-weight: 600;height:0px">{name}</h3>',
                    '<br/><i class="fa-phone-square fa x-fa-logo"></i> 手机：<span class="list-view-txt">{phone}</span> ',
                    '<br/><i class="fa-envelope-square fa x-fa-logo"></i> 邮箱：<span class="list-view-txt">{emali}</span>',
                    '<br/><i class="fa-qq fa x-fa-logo"></i> QQ：<span class="list-view-txt">{qq}</span>',
                    '<br/></i> 账号：<span class="list-view-txt">{uname}</span>',
                    '<br/>身份证：<span class="list-view-txt">{idCard}</span>',
                    '<br/><br/><a href="javascript:void(1)" onclick=\'admin_changeUserSate("{id}")\'><i class="fa-pencil-square fa x-fa-logo font-white"></i>&nbsp;修改状态</a>&nbsp;&nbsp;&nbsp;<a href="javascript:void(1)" onclick=\'admin_resetPwd("{id}")\'><i class="fa-exclamation-triangle fa x-fa-logo font-white"></i>&nbsp;重置密码</a>',
                    '</div></div></tpl>', {
                        getCls: function (state) {
                            return state == '1' ? 'x-fa-label-green' : (state == '0' ? 'x-fa-label-red' : 'x-fa-label-ogn');
                        }
                    }),
            order: ['createDate->desc'],
            top: [{
                xtype: 'textfield',
                op: 'like',
                name: 'name'
            }, {
                xtype: 'textfield',
                op: 'like',
                name: 'phone'
            }, $.search],
            columns: [{
                text: '所属企业域',
                width: 150,
                locked: true,
                "name": "organ.organName"
            }, {
                locked: true,
                name: 'state',
                renderer: $.dicRenderer('userState')
            }, {
                locked: true,
                width: 100,
                name: 'name'
            }, {
                width: 100,
                text: '岗位',
                "name": "positionId.positionName"
            }, {
                width: 150,
                "name": "phone"
            }, {
                width: 200,
                "name": "emali"
            }, {
                width: 200,
                "name": "idCard"
            }, {
                "name": "qq",
                width: 200
            }, {
                name: 'createDate',
                width: 150
            }]
        }]

    })
}

function admin_resetPwd(id) {
    var grid = $('BasicUser_main');
    grid.select(grid.getStore().getById(id));
    grid.rowRequest({
        url: 'admin/resetPwd',
        msg: '确定重置该用户密码吗？重置后密码同一为888888.',
        callback: function (text) {
            if (text) {
                $.show('密码重置成功!');
            }
        }
    });
}

function admin_changeUserSate(id) {
    var grid = $('BasicUser_main');
    grid.select(grid.getStore().getById(id));
    var sel = grid.select()[0];
    var cmd = function (state) {
        var oldState = sel.get('state');
        if (oldState == state) {
            return $.error('状态没有发生改变无需修改。')
        }
        $.cmd({
            clazz: BasicUser,
            type: 'save',
            params: {
                id: sel.get('id'),
                state: state
            },
            callback: function () {
                grid.search();
                $.show('状态修改成功!');
                win.close();
            }
        });
    }
    var win = $({
        modal: true,
        title: '修改用户状态',
        xtype: 'window',
        bodyPadding: 40,
        html: Ext.String.format('您正在修改账户为【{0}】的状态.', sel.get('uname')),
        buttons: [{
            cls: 'green',
            text: '启用',
            handler: function () {
                cmd('1');
            }
        }, {
            cls: 'red',
            text: '停封',
            handler: function () {
                cmd('0');
            }
        }, $.cancel],
        width: 350
    }).show();
}